cmake_minimum_required(VERSION 3.10)

# 
project(RC_lower VERSION 1.0 LANGUAGES CXX)

# 
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

# specific your options 
set(RC_BUILD_TARGET "core" CACHE STRING "choos building target: core/mpc_v2")
option(INPUT_USE_REAL "INPUT Use real enviornment" OFF)
option(OUTPUT_USE_REAL "OUTPUT Use real enviornment" OFF)

# openMP settings
FIND_PACKAGE(OpenMP REQUIRED)
if (OPENMP_FOUND)
    message("OPENMP FOUND")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif ()

# Eigen
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIRS})

# OPENBLAS
find_package(OpenBLAS REQUIRED)
include_directories(${OpenBLAS_INCLUDE_DIRS})

# homo_ocp
find_library(HOMO_OCP_LIBRARY homo_ocp)

# ==========================可执行文件==========================

# include files
include_directories(
    ./chassis
    ./core
    ./estimator
    ./tracking
    ./estimate_problem
    ../dependency/Noploop_UWB
    ../dependency/WHEELTEC_IMU
    ../dependency/WitMotion_RTK
    ../dependency/MKS_VESC
    ../dependency/cpp_tools
    ../communicate
)

file(GLOB DEPEND_SOURCES 
    ./estimate_problem/*.cpp
    ../dependency/Noploop_UWB/*.c
)

if (RC_BUILD_TARGET STREQUAL "core")
    message("=========build core=========")
    add_definitions(-DHOMO_OCP_USE_MA97)

    file(GLOB SOURCES 
        ./run/lower.cpp
    )
elseif  (RC_BUILD_TARGET STREQUAL "mpc_v2")
    message("=========build mpc_v2=========")
    add_definitions(-DHOMO_OCP_USE_MA97)
    
    file(GLOB SOURCES 
        ./run/mpc_v2.cpp
    )
endif ()

add_executable(lower 
    ${DEPEND_SOURCES}
    ${SOURCES}
)

target_link_libraries(lower
    ${OpenBLAS_LIBRARIES}
    homo_ocp
    tinyxml2
    serialib
)

if (INPUT_USE_REAL)
    message("=========input real=========")
    
    add_definitions(-DINPUT_REAL)
else (INPUT_USE_REAL)
    message("=========input sim=========")
endif (INPUT_USE_REAL)
    
if (OUTPUT_USE_REAL)
    message("=========output real=========")

    add_definitions(-DOUTPUT_REAL)

    target_link_libraries(lower  
        wiringPi
    )
else (OUTPUT_USE_REAL)
    message("=========output sim=========")
endif (OUTPUT_USE_REAL )
